<template>
  <div class="box">
    <el-container class="adminHome-container">
      <!-- 侧边栏-->
      <el-aside :width="isCollapse ? '64px' : '256px'">
        <span class="index-title">
          <img :src="logob"  alt="LOGO"/>
          <span class="logo-text" v-show="!isCollapse">新生报到管理系统</span>
        </span>
        <el-menu
            background-color="#ffffff"
            text-color="#000"
            active-text-color="#1890FF"
            unique-opened
            router
            :default-active="activePath"
            :collapse="isCollapse"
            :collapse-transition="false">
          <!-- 一级菜单-->
          <el-menu-item class="index" index="../index" key="index" @click="saveNavState('../index')">
            <template>
              <!-- 图标-->
              <i class="el-icon-s-home"></i>
              <!-- 文本-->
              <span>首页</span>
            </template>
          </el-menu-item>
          <el-submenu :index="item.menuId" v-for="item in menuList" :key="item.menuId">
            <!-- 一级菜单的模板区域-->
            <template slot="title">
              <!-- 图标-->
              <i :class="item.menuIcon" id="icon"></i>
              <!-- 文本-->
              <span>{{ item.menuName }}</span>
            </template>
            <el-menu-item :index="subItem.menuPath" v-for="subItem in item.menuChildren" :key="subItem.menuId"
                          @click="saveNavState(subItem.menuPath)">
              <template slot="title">
                <i :class="subItem.menuIcon" id="icon2"></i>
                <span>{{ subItem.menuName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 页面主体区域-->
      <el-container>
        <!-- 头部区域-->
        <el-header>
          <div class="nav-bar-container">
            <el-row :gutter="15">
              <el-col :xs="4" :sm="12" :md="12" :lg="12" :xl="12">
                <div class="left-panel">
                  <i
                      :class="collapse ? 'el-icon-s-fold' : 'el-icon-s-unfold'"
                      :title="collapse ? '收起' : '展开'"
                      class="fold-unfold"
                      @click="handleCollapse"
                  ></i>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-header>
        <!--右侧内容主体-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
// eslint-disable-next-line no-unused-vars
import logo from '../../assets/f2.png';
export default {
  name: "AdminHome",
  data() {
    return {
      logob: logo,
      // 左侧菜单列表
      menuList: [],
      // 被激活的链接地址
      activePath: '',
      pulse: false,
      collapse: true,
      isCollapse: false
    }
  },
  created() {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    handleCollapse() {
      this.changeCollapse()
    },
    changeCollapse() {
      this.collapse = !this.collapse
      this.isCollapse = !this.isCollapse
    },
    // 获取所有的菜单
    async getMenuList() {
      this.user = JSON.parse(window.sessionStorage.getItem("user"));
      this.loginName = this.user.loginName
      const {data:res } = await this.$http.get("getMenuByAuthority?loginName=" + this.loginName)
      // console.log(res)
      if (res.code != 200) return this.$message.error('获取菜单列表失败')
      this.menuList = res.data
      // console.log(res)
      this.menuList[1].menuChildren.menuName
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    },
  },
}
</script>

<style lang="less" scoped>
div {
  height: 100%;
}
.adminHome-container {
  height: 100%;
}
.el-header {
  background-color: #ffffff;
  padding-left: 18px;
  text-align: left;
  height: 72px !important;
  line-height: 88px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #607AB7;
  font-size: 22px;
  > div {
    display: flex;
    align-items: center;
    > span {
      margin-left: 8px;
    }
  }
}
.el-aside {
  background-color: #fff;
  text-align: left;
  box-shadow: 0 0 8px 1px #969896;
  z-index: 20;
  margin-top: 0 !important;
    .index-title {
      display: inline-block;
      height: 72px;
      width: 100%;
      line-height: 72px;
      text-align: center;
      background: #f4f4fa;
      img {
        width: 26px;
        height: 36px;
        vertical-align: middle;
      }
      .logo-text {
        font-size: 22px;
        margin-left: 6px;
        vertical-align: middle;
        color: #0090F2;
      }
    }
    .el-menu {
    border-right: 0;
  }
  .index {
    background-color: #fff !important;
  }

  #icon,#icon2 {
    margin-right: 6px;
  }
}
.el-main {
  background: #F0F0FA;
}

</style>
